package org.zoffy.utils;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class HttpUtils {
    private static volatile HttpClient httpClient;
    private static HttpClient getInstance() {
        if(httpClient == null) {
            synchronized (HttpUtils.class) {
                if(httpClient == null) {
                    httpClient = HttpClients.createDefault();
                }
            }
        }
        return httpClient;
    }
    public static String get(String url) throws IOException {
        HttpClient client = getInstance();
        HttpGet request = new HttpGet(url);
        HttpResponse response = client.execute(request);
        return EntityUtils.toString(response.getEntity());
    }
}
